package com.yoomiito.app.ui.anyview.goodsinfo.bottom;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.yoomiito.app.R;
import com.yoomiito.app.base.App;
import com.yoomiito.app.base.BaseActivity;
import com.yoomiito.app.interf.BaseBottomBar;
import com.yoomiito.app.model.bean.GoodsDetail;
import com.yoomiito.app.ui.order.sureorder.singleGoods.BuyGoodsActivity;
import com.yoomiito.app.utils.AllCode;
import com.yoomiito.app.utils.RouterUtils;
import com.yoomiito.app.utils.SpannableUtils;
import com.yoomiito.app.utils.Type;
import com.yoomiito.app.utils.UserInfoConfig;

public class YouPinBottomBar extends BaseBottomBar {
    private LinearLayout mAwardLl;
    private TextView mAwardTv;
    private TextView mShareAwardTv;
    private TextView mShareContentTv;

    public YouPinBottomBar(Context context, boolean isLogin) {
        super(context, isLogin);
        LayoutInflater.from(mContext).inflate(R.layout.youpin_bottom_btn, this, true);
        initView();
    }

    private void initView() {
        mAwardLl = findViewById(R.id.award_ll);
        mAwardTv = findViewById(R.id.award);
        mShareAwardTv = findViewById(R.id.show_award);
        mShareContentTv = findViewById(R.id.share_bottom);
        findViewById(R.id.bg_3).setOnClickListener(v -> {//分享
            if (checkClick()){
                RouterUtils.toShareGoods((BaseActivity) mContext, String.valueOf(mGoodsDetail.getNum_iid()), AllCode.YouPin);
            }
        });
        findViewById(R.id.bg_2).setOnClickListener(v -> {//购买
            if (checkClick()){
                BuyGoodsActivity.start(mContext, mGoodsDetail, AllCode.YouPin);
//                ((BaseActivity)mContext).showLoading();
//                canBuy(String.valueOf(mGoodsDetail.getNum_iid()))
//                        .subscribe(new ApiSubscriber<BaseRepository>() {
//                            @Override
//                            public void onSuccess(BaseRepository baseModel) {
//                            }
//
//                            @Override
//                            public void onFail(ApiException error) {
//                                YMToast.showText(error.getMsg());
//                            }
//                        });

            }
        });
    }


    @Override
    public void updateInfo(GoodsDetail detail) {
        super.updateInfo(detail);
        if (App.mAppConfig.getIsLogin()) {
//            if (UserInfoConfig.getRoleId() >= LevelType.VIP_4) {
            if (!SpannableUtils.isEmptyOr0(detail.getShare_money())){
                mShareAwardTv.setText("奖励¥" + SpannableUtils.handlePrice(detail.getShare_money()));
                mShareAwardTv.setVisibility(View.VISIBLE);
            }
            if (UserInfoConfig.getRoleId() >= Type.LevelType.VIP_7&&!SpannableUtils.isEmptyOr0(detail.getGet_money())) {
                mAwardTv.setText("返佣 ¥" + SpannableUtils.handlePrice(detail.getGet_money()));
                mAwardLl.setVisibility(View.VISIBLE);
//            } else {
//                mShareContentTv.setText("分享");
//                mAwardLl.setVisibility(View.GONE);
//                mShareAwardTv.setVisibility(View.GONE);
            }
        }
    }
}
